﻿using System;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;

[Serializable]
public class SerializableMesh
{
    [CompilerGenerated]
    private static Func<Vector3, SerializableVector3> <>f__am$cache4;
    [CompilerGenerated]
    private static Func<Vector2, SerializableVector2> <>f__am$cache5;
    [CompilerGenerated]
    private static Func<SerializableVector3, Vector3> <>f__am$cache6;
    [CompilerGenerated]
    private static Func<SerializableVector2, Vector2> <>f__am$cache7;
    [NonSerialized]
    private Mesh m_Mesh;
    public int[] triangles;
    public SerializableVector2[] uv;
    public SerializableVector3[] vertices;

    public SerializableMesh(Mesh mesh)
    {
        if (mesh != null)
        {
            if (<>f__am$cache4 == null)
            {
                <>f__am$cache4 = new Func<Vector3, SerializableVector3>(SerializableMesh.<SerializableMesh>m__18C);
            }
            this.vertices = mesh.vertices.Select<Vector3, SerializableVector3>(<>f__am$cache4).ToArray<SerializableVector3>();
            this.triangles = mesh.triangles;
            if (<>f__am$cache5 == null)
            {
                <>f__am$cache5 = new Func<Vector2, SerializableVector2>(SerializableMesh.<SerializableMesh>m__18D);
            }
            this.uv = mesh.uv.Select<Vector2, SerializableVector2>(<>f__am$cache5).ToArray<SerializableVector2>();
            this.mesh = mesh;
        }
    }

    [CompilerGenerated]
    private static SerializableVector3 <SerializableMesh>m__18C(Vector3 x)
    {
        return x;
    }

    [CompilerGenerated]
    private static SerializableVector2 <SerializableMesh>m__18D(Vector2 x)
    {
        return x;
    }

    public static implicit operator Mesh(SerializableMesh v)
    {
        return v.mesh;
    }

    public static implicit operator SerializableMesh(Mesh v)
    {
        return new SerializableMesh(v);
    }

    public Mesh mesh
    {
        get
        {
            if (this.m_Mesh == null)
            {
                this.m_Mesh = new Mesh();
                if (<>f__am$cache6 == null)
                {
                    <>f__am$cache6 = x => (Vector3) x;
                }
                this.m_Mesh.vertices = this.vertices.Select<SerializableVector3, Vector3>(<>f__am$cache6).ToArray<Vector3>();
                this.m_Mesh.triangles = this.triangles;
                if (<>f__am$cache7 == null)
                {
                    <>f__am$cache7 = x => (Vector2) x;
                }
                this.m_Mesh.uv = this.uv.Select<SerializableVector2, Vector2>(<>f__am$cache7).ToArray<Vector2>();
                this.m_Mesh.RecalculateNormals();
                this.m_Mesh.RecalculateBounds();
                this.m_Mesh.Optimize();
            }
            return this.m_Mesh;
        }
        set
        {
            this.m_Mesh = value;
        }
    }
}

